/*
 * TestTextStorageStuff.cpp
 *
 *  Created on: 28/10/2009
 *      Author: ngonzalez
 */

#include <iostream>
#include "Bloque.h"
#include "Registro.h"
#include "../Externa/Clave.h"
#include "../Externa/Dato.h"
#include "Alumno.h"
#include "../StorageResourceFactory.h"
#include "ArchivoTexto.h"
#include <ctime>


using namespace std;

class TestTextStorageStuff {

	StorageResourceFactory *storageResourceFactory;
	StorageResource *storageResource;
	string fileName;

public:

	void Setup () {
		storageResourceFactory = new StorageResourceFactory();
		storageResourceFactory->createStorageTextResource("Testing_31_19.txt");
		storageResource = storageResourceFactory->getStorageResource();
	}

	void Terminar () {
		delete storageResourceFactory;
		cout << "El test de TestTextStorageStuff se completo"<< endl;
	}

	void testSaveData () {
	    Alumno *alumno = new Alumno();
	    alumno->setDni("011112222222");
		storageResource->setData(alumno);
		Clave clave("LaLa",storageResource->getDato());
		storageResource->setClave(&clave);
		storageResource->saveData();

	}

	void testSaveDataList () {
	    list <Dato*> alumnos;
	    list<Dato*>::iterator iterator;

	    Alumno *alumno = new Alumno();
	    alumno->setDni("111");
	    alumnos.insert(alumnos.end(),alumno);

	    Alumno *alumno2 = new Alumno();
	    alumno2->setDni("222");
	    alumnos.insert(alumnos.end(),alumno2);

	    Alumno *alumno3 = new Alumno();
	    alumno2->setDni("333");
	    alumnos.insert(alumnos.end(),alumno3);

	    storageResource->setData(alumnos);
	    storageResource->saveData();
	}

	void testUpdateData(){
		Alumno *alumnmo3 = new Alumno();
		alumnmo3->setDni("123456d789");
		alumnmo3->setNombre("Testingggggg");

		Clave *clave = new Clave("",alumnmo3);
		storageResource->updateData(alumnmo3,clave);
		delete alumnmo3;
		delete clave;
	}

	void testDeleteData(){
		Clave *clave = new Clave();
		clave->valorClave = "0000000000";
//		clave->valorClave = "1111111111";
//		clave->valorClave = "2222222222";
		storageResource->deleteData(clave);
		delete clave;
	}

	void Run() {
		Setup();
		testSaveData();
//		testDeleteData();
//		testUpdateData();
//		testSaveDataList();
//		Terminar();
	}

};
